# *Replication File for
# Lawmaking and Presidential Attributes in the Chilean Constitution: What's the Urgency?
# Sergio Huertas-Hernandez and Valeria Palanza
# PS: Political Science & Politics


# Packages

library(here)
library(tidyverse)
library(ggpubr)
library(ggrepel)
library(readxl)


# Load database

Senate <- read_excel("Excel Data to Replicate Figure 3.xlsx", sheet = "CA")
names (Senate)

Chamber <- read_excel("Excel Data to Replicate Figure 3.xlsx", sheet = "CB")
names (Chamber)


# Graph (a) Senate

library("reshape2")  

data_long <- melt(Senate, id = "legyear")

text <- "Bachelet I"

text1 <- "Piñera  I"


gfg_plot <- ggplot(data_long,            
                   aes(x = legyear,
                       y = value,
                       color = variable, linetype=variable)) +  geom_line()  +
  geom_point(aes(shape=variable, color=variable), show.legend = FALSE) + 
  scale_color_manual("", values = c("#000000", "#646464", "#727272"), aesthetics = c("color", "fill")) +
  scale_linetype_manual("", values = c("longdash", "solid", "dashed")) +
  scale_x_continuous(breaks = seq(min(Senate$legyear), max(Senate$legyear), by = 1)) +
  scale_y_continuous(breaks = seq(0,700, by = 100), 
                     limits = c(0, 700)) +
  labs(title = "(a)  Senate", x = "", y = "Number of bills marked urgent") + 
  annotate ("text",x = 2008,y = 0, label = text) +
  annotate ("text",x = 2012,y = 0, label = text1) +
  geom_vline(xintercept = 2010, linetype="dotdash") +
  theme_bw()+
  theme(axis.ticks = element_blank(),
        legend.position = "bottom",
        axis.text = element_text(size=15),
        legend.text = element_text(size=15),
        axis.title.x = element_text(size = 16),
        axis.title.y = element_text(size = 16),
        plot.title = element_text(hjust = 0.5)) 
                     
gfg_plot



# Graph (b) Lower Chamber

data_long1 <- melt(Chamber, id = "legyear")

text <- "Bachelet I"

text1 <- "Piñera  I"


gfg_plot1 <- ggplot(data_long1,            
                   aes(x = legyear,
                       y = value,
                       color = variable, linetype=variable)) +  geom_line()  +
  geom_point(aes(shape=variable, color=variable), show.legend = FALSE) + 
  scale_color_manual("", values = c("#000000", "#646464", "#727272"), aesthetics = c("color", "fill")) +
  scale_linetype_manual("", values = c("longdash", "solid", "dashed")) +
  scale_x_continuous(breaks = seq(min(Senate$legyear), max(Senate$legyear), by = 1)) +
  scale_y_continuous(breaks = seq(0,700, by = 100), 
                     limits = c(0, 700)) +
  labs(title = "(b)  Lower Chamber", x = "", y = "") + 
  annotate ("text",x = 2008,y = 0, label = text) +
  annotate ("text",x = 2012,y = 0, label = text1) +
  geom_vline(xintercept = 2010, linetype="dotdash") +
  theme_bw()+
  theme(axis.ticks = element_blank(),
        legend.position = "bottom",
        axis.text = element_text(size=15),
        legend.text = element_text(size=15),
        axis.title.x = element_text(size = 16),
        axis.title.y = element_text(size = 16),
        plot.title = element_text(hjust = 0.5)) 

gfg_plot1

# Join graphs (a) and (b)

fig3  <- ggarrange(gfg_plot, gfg_plot1, ncol = 2, nrow = 1, legend.grob = get_legend(gfg_plot), legend = "bottom")

# Figure 3. Bills passed with urgency during Bachelet I and Piñera I

fig3



